Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Two "=" characters in a string

How to check in javascript if in the string there are two "=" symbols and to throw a mistake (beacuse for example 1+=2=3 is wrong but 1+2=3 is right)

about 4 years ago · Santiago Gelvez
3 Respostas
Responde à pergunta

0

function validateText() {
  const text = document.getElementById('text').value;
  if ((text.match(/=/g)?.length || 0) < 2) {
    document.getElementById('result').innerHTML = "Valid";
  } else {
    document.getElementById('result').innerHTML = "Invalid";
  }
}
<textarea id="text"></textarea>

<button onclick=validateText()>Validate</button>

<p id="result"></p>

about 4 years ago · Santiago Gelvez Relatório

0

var input_true = '1 + = 2 +  3';
var input_false = '1 + = 2 + = 3';

var success = /^[^=]*=[^=]*$/.test(input_true);      // pass
var not_success = /^[^=]*=[^=]*$/.test(input_false); // fails
about 4 years ago · Santiago Gelvez Relatório

0

Write a little function that uses a regex to test for this.

function tester(str) {
  return str.match(/=/g).length === 1;
}

console.log(tester('='));
console.log(tester('Bob=='));
console.log(tester('Bob='));
console.log(tester('=Bob=='));

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda